<template>
  <div class="category-con">
    <van-sticky :offset-top="0">
      <div class="search">
        <span class="icon-search">
          <img src="imgs/icon-search.png" alt="">
        </span>
        <span class="content">搜索商品名称</span>
      </div>
    </van-sticky>
    <van-sidebar v-model="activeKey" @change="onChange">
      <van-sidebar-item title="Xiaomi 系列" />
      <van-sidebar-item title="Redmi  系列" />
      <van-sidebar-item title="笔记本" />
      <van-sidebar-item title="游戏手机" />
    </van-sidebar>
    <div class="box">
      <div class="img">
        <img :src="productList.headerImgUrl" alt="">
      </div>
      <router-link :to="`/product/${item.id}`" class="product-item" v-for="(item,index) in productList.list" :key="index">
        <div class="product-img">
          <img v-lazy="item.imgUrl" alt="">
        </div>
        <div class="product-msg">
          <h2>{{item.name}}</h2>
          <p class="price">￥{{item.price}}元起 <span class="status" v-show="item.status">{{item.status}}</span></p>
        </div>
      </router-link>
    </div>
  </div>
</template>

<script>
export default {
  // eslint-disable-next-line vue/multi-word-component-names
  name: 'Category',
  data() {
    return {
      activeKey: 0,
      productList: {}
    }
  },
  mounted() {
    this.getProductList()
  },
  methods: {
    // 切换显示的商品类型
    async onChange(index) {
      const res = await this.$API.categoryList(index)
      this.productList = res.data
    },
    // 初始化获取手机数据
    async getProductList() {
      const res = await this.$API.categoryList(0)
      this.productList = res.data
    }
  }
}
</script>

<style lang="less" scoped>
.category-con {
  .search {
    display: flex;
    align-items: center;
    width: 656px;
    height: 60px;
    margin: 0 auto;
    background-color: #f7f7f7;
    border-radius: 30px;
    .icon-search {
      display: inline-block;
      width: 60px;
      text-align: center;
      img {
        width: 50px;
      }
    }
    .content {
      margin-left: 10px;
      color: #a7a7a7;
      font-size: 30px;
    }
  }
  .box {
    width: 720px;
    margin: 0 auto;
    padding-left: 200px;
    .img {
      width: 490px;
      img {
        width: 100%;
        height: auto;
      }
    }
    .product-item {
      display: flex;
      justify-content: flex-start;
      width: 504px;
      height: 147px;
      background: #f8f8f8;
      margin-top: 25px;
      border-radius: 12px;
      padding: 7px;
      color: black;
      font-size: 28px;
      .product-img {
        float: left;
        img {
          width: 133px;
          height: 133px;
        }
      }
      .product-msg {
        padding: 25px 0 0 10px;
        .price {
          padding-top: 15px;
          .status {
            width: 40px;
            height: 25px;
            border: 2px solid #e5c8ac;
            padding: 0 9px;
            border-radius: 5px;
            color: #e5c8ac;
            margin-left: 15px;
          }
        }
      }
    }
  }
}
</style>
<style lang='less' scoped>
/deep/ .van-sidebar {
  position: fixed;
  top: 60;
  left: 0;
  width: 200px;
}
/deep/ .van-sidebar-item {
  background-color: #fff;
  height: 90px;
  font-size: 28px;
  line-height: 50px;
  text-align: center;
  color: #666666;
}
/deep/ .van-sidebar-item--select {
  color: black;
  font-weight: 700;
}
</style>
